home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / beebe / c / dvil3p < prev    next >
Encoding:
Text File  |  1990-12-18  |  11.0 KB  |  349 lines

  1. /* -*-C-*- dvil3p.c */
  2. /*-->dvil3p*/
  3. /**********************************************************************/
  4. /******************************* dvil3p *******************************/
  5. /**********************************************************************/
  6.  
  7. #include "dvihead.h"
  8.  
  9. /**********************************************************************/
  10. /************************  Device Definitions  ************************/
  11. /**********************************************************************/
  12.  
  13. /* All output-device-specific definitions go here.  This section must
  14. be changed when modifying a dvi driver for use on a new device */
  15.  
  16. #undef DECLN03PLUS
  17. #define  DECLN03PLUS 1                  /* conditional compilation flag */
  18.  
  19. #undef HIRES                            /* this is 150 dpi version */
  20. #define  HIRES            1             /* define for 300 dpi version */
  21.  
  22. #define VERSION_NO      "2.10"          /* DVI driver version number */
  23.  
  24. #if    HIRES
  25. #define  DEVICE_ID      "Digital LN03-PLUS 300 dpi laser printer"
  26.                                         /* this string is printed at runtime */
  27. #define  XDPI           300             /* horizontal dots/inch */
  28. #define  YDPI           300             /* vertical dots/inch */
  29. #else
  30. #define  DEVICE_ID      "Digital LN03-PLUS 150 dpi laser printer"
  31.                                         /* this string is printed at runtime */
  32. #define  XDPI           150             /* horizontal dots/inch */
  33. #define  YDPI           150             /* vertical dots/inch */
  34. #endif
  35.  
  36. #define OUTFILE_EXT     "l3p"
  37.  
  38. #define  BYTE_SIZE        7             /* output file byte size */
  39.  
  40. #undef STDRES
  41. #define STDRES  1               /* 0 for low-resolution devices */
  42.  
  43. #define  V6SIZE         XSIZE
  44. #define  XPSIZE         8               /* horizontal paper size in inches */
  45. #define  XSIZE          (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  46.                                 (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  47.                                         /* number of horizontal dots; */
  48.                                         /* MUST BE multiple of */
  49.                                         /* 2*HOST_WORD_SIZE */
  50. #define  XWORDS         ((XSIZE + HOST_WORD_SIZE - 1)/HOST_WORD_SIZE)
  51.                                         /* number of words in rows  */
  52.                                         /* of bitmap array */
  53. #define  YPSIZE         11              /* vertical paper size in inches */
  54. #define  YSIZE          (YDPI*YPSIZE)   /* number of vertical dots */
  55.  
  56. /* The printer bit map (must have a multiple of 6 rows) */
  57.  
  58. #define XBIT ((1+2*XWORDS)/2)
  59. #define YBIT (((YSIZE+5)/6)*6)
  60.  
  61. #if    (IBM_PC_LATTICE | IBM_PC_MICROSOFT | IBM_PC_WIZARD)
  62. #undef SEGMEM
  63. #define SEGMEM 1 /* ( ((long)XBIT * (long)YBIT) > 65536L ) */
  64. #endif
  65.  
  66. #include "bitmap.h"
  67.  
  68.  
  69. #include "main.h"
  70. #include "abortrun.h"
  71. #include "actfact.h"
  72. #include "alldone.h"
  73. #include "chargf.h"
  74. #include "charpk.h"
  75. #include "charpxl.h"
  76. #include "clrbmap.h"
  77. #include "clrrow.h"
  78. #include "dbgopen.h"
  79.  
  80. /*-->devinit*/
  81. /**********************************************************************/
  82. /****************************** devinit *******************************/
  83. /**********************************************************************/
  84.  
  85. void
  86. devinit(argc,argv)              /* initialize device */
  87. int argc;
  88. char *argv[];
  89. {
  90.     (void)getbmap();
  91.     if (runlengthcode && !quiet)
  92.     {
  93.         (void)fprintf(stderr,"[Run-length encoding of output file]");
  94.         NEWLINE(stderr);
  95.     }
  96. }
  97.  
  98. /*-->devterm*/
  99. /**********************************************************************/
  100. /****************************** devterm *******************************/
  101. /**********************************************************************/
  102.  
  103. void
  104. #ifdef __STDC__
  105. devterm(void)                       /* terminate device */
  106. #else
  107. devterm()                       /* terminate device */
  108. #endif
  109. {
  110. }
  111.  
  112. #include "dispchar.h"
  113. #include "dvifile.h"
  114. #include "dviinit.h"
  115. #include "dviterm.h"
  116. #include "f20open.h"
  117. #include "fatal.h"
  118. #include "fillrect.h"
  119. #include "findpost.h"
  120. #include "fixpos.h"
  121. #include "fontfile.h"
  122. #include "fontsub.h"
  123. #include "getbmap.h"
  124. #include "getbytes.h"
  125. #include "getfntdf.h"
  126. #include "getpgtab.h"
  127. #include "inch.h"
  128. #include "initglob.h"
  129. #include "loadchar.h"
  130. #include "movedown.h"
  131. #include "moveover.h"
  132. #include "moveto.h"
  133. #include "nosignex.h"
  134. #include "openfont.h"
  135. #include "option.h"
  136.  
  137. /*-->outline*/
  138. /**********************************************************************/
  139. /****************************** outline *******************************/
  140. /**********************************************************************/
  141.  
  142. void
  143. outline(pline)
  144. char *pline;                            /* pointer to raster line */
  145. {
  146.    /* On return, the caller must output the character that selects the
  147.       spacing to the next line */
  148.  
  149.     register INT16 left;
  150.     register char *a,*b,*c;
  151.     INT16 len;
  152.  
  153.     for ((left = V6SIZE, c = pline + V6SIZE - 1);
  154.         (*c == '\077') && (left > 1);
  155.         (--left,--c))                   /* trim white space but leave */
  156.         ;                               /* at least 1 character in line */
  157.  
  158.     /*******************************************************************
  159.     We search for runs as follows.  "b" marks the beginning of unwritten
  160.     data, and "a" anchors the beginning of a run which continues to just
  161.     before "c".   The  run length  is  "c"-"a".  Since  the  run  length
  162.     encoding carries a penalty of additional output equal to the  length
  163.     of the  run  length  prefix (!<number>), short runs are not encoded.
  164.  
  165.     If a long  enough run  is found,  then the  string "b"  .. "a"-1  is
  166.     output since its length is now  known, followed by the run  encoding
  167.     for the character at "a".  Then "a" and "b" are advanced to "c", and
  168.     the scan continues.
  169.  
  170.     If the  run  beginning at  "a"  is too  short,  then "a"  is  simply
  171.     advanced.
  172.  
  173.     We do not store a termination marker, but instead  keep  a  counter,
  174.     "left", which is  decremented to  0 when the  end of  the string  is
  175.     reached.
  176.  
  177.     ?????????????xxxxxxxxxxxxxxxx????????????????????
  178.     ^            ^               ^
  179.     |            |               |
  180.     b            a               c
  181.  
  182.                  <-----run------>
  183.     *******************************************************************/
  184.  
  185.     if (runlengthcode && (left > 3))
  186.     {
  187.         for (a = b = pline; (left > 0); --left)
  188.         {
  189.             for (c = a; (*a == *++c) && left; --left)
  190.                 ;                           /* advance over run */
  191.             len = (INT16)(c-a);             /* "c" points past run */
  192.             if (len > 3)                    /* output long run */
  193.             {
  194.                 if (a > b)                  /* output previous string */
  195.                 {
  196.                     for ( ; b < a; b++)
  197.                         OUTC(*b);
  198.                 }
  199.                 OUTF2("!%d%c",len,*a);
  200.                 a = b = c;
  201.             }
  202.             else                            /* ignore short run */
  203.             {
  204.                 ++a;
  205.                 left += len - 1;
  206.             }
  207.         }
  208.         if (a > b)          /* output remaining string */
  209.         {
  210.             for ( ; b < a; b++)
  211.                 OUTC(*b);
  212.         }
  213.     }
  214.     else                                /* no runlength coding */
  215.     {
  216.        for (c = pline; left; --left, c++)
  217.            OUTC(*c);
  218.     }
  219. }
  220.  
  221. #include "outrow.h"
  222.  
  223. /*-->prtbmap*/
  224. /**********************************************************************/
  225. /****************************** prtbmap *******************************/
  226. /**********************************************************************/
  227.  
  228. void
  229. #ifdef __STDC__
  230. prtbmap(void)
  231. #else
  232. prtbmap()
  233. #endif
  234. {
  235.     register char *c;                   /* pointer into v6[] */
  236.     UNSIGN32 *p;                        /* pointer into bitmap[][] */
  237.     register UNSIGN32 mask;             /* mask for single bit selection */
  238.     INT16 i,j,k,ybottom,ytop;
  239.     char v6[V6SIZE];                    /* vertical 6-bit raster encodings */
  240.  
  241. #if    SEGMEM
  242.     UNSIGN32* q[6];                     /* pointers to 6 raster lines */
  243. #define Q(n) q[n]                       /* use precomputed pointers */
  244. #else /* NOT SEGMEM */
  245. #define Q(n) (p - (n)*XBIT)             /* compute pointers on the fly */
  246. #endif /* SEGMEM */
  247.  
  248.     ytop = YSIZE-1;
  249.  
  250.     k = -1;         /* find bottom non-zero raster */
  251.     for (j = 0; (j < ytop) && (k < 0); ++j) /* loop over raster lines */
  252.     {
  253.  
  254. #if    IBM_PC_MICROSOFT
  255.         for (k = XBIT - 1; ((k >= 0) && (*BITMAP(j,k) == 0)); --k)
  256.             ;                           /* trim white space */
  257. #else
  258.         p = BITMAP(j,XBIT-1);
  259.         for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  260.             --p;                        /* trim white space */
  261. #endif
  262.  
  263.     }
  264.     ybottom = MAX(0,6*((j-1)/6));       /* need 6n raster lines */
  265.  
  266. #if    HIRES
  267.     /* <CR><ESC>[7 I<ESC>P0;0;1q"1;1 for 300 dpi spacing */
  268.     OUTS("\015\033[7 I\033P0;0;1q\0421;1");
  269. #else
  270.     /* <CR><ESC>[7 I<ESC>P0;0;2q"1;1 for 150 dpi spacing */
  271.     OUTS("\015\033[7 I\033P0;0;2q\0421;1");
  272. #endif
  273.  
  274.     for (j = ytop; (j >= ybottom) ; j -= 6)    /* loop over raster lines */
  275.                                                /* in groups of 6 */
  276.     {
  277. #if    SEGMEM
  278. #else
  279.         p = BITMAP(j,0);        /* the j-th raster line */
  280. #endif
  281.  
  282.         c = &v6[0];             /* vertical 6-bit encodings */
  283.         for (i = 0; i < XBIT; (++p,++i))        /* loop over raster words */
  284.         {
  285.             /* PCC-20 compiled (1 << (HOST_WORD_SIZE-1)) to 0, so do it the
  286.                hard way, arghh... */
  287.             mask = 1;
  288.             mask <<= (HOST_WORD_SIZE-1);        /* to select leftmost bit */
  289.  
  290. #if    SEGMEM
  291.             for (k = 0; k < 6; ++k)     /* compute pointers to 6 rasters */
  292.                 q[k] = BITMAP(j-k,i);
  293. #endif
  294.  
  295.             for (k = 0; k < HOST_WORD_SIZE; (++c,++k))/* loop over word bits */
  296.             {
  297.                 /* examine bits in 6 adjacent rows and build 6-bit */
  298.                 /* character value */
  299.                 *c = '\0';              /* clear character template */
  300.                 if (*Q(0) & mask)
  301.                     *c |= '\001';
  302.                 if (*Q(1) & mask)
  303.                     *c |= '\002';
  304.                 if (*Q(2) & mask)
  305.                     *c |= '\004';
  306.                 if (*Q(3) & mask)
  307.                     *c |= '\010';
  308.                 if (*Q(4) & mask)
  309.                     *c |= '\020';
  310.                 if (*Q(5) & mask)
  311.                     *c |= '\040';
  312.                 mask >>= 1;             /* move masking bit right 1 position */
  313.                 *c += '\077';           /* bias 6-bit value by 63 */
  314.             }
  315.         };
  316.         outline(&v6[0]);
  317.         OUTS("-\n");
  318.     }
  319.     /* Terminate the graphics image */
  320.     /* <ESC>\<FF>
  321.     */
  322.     OUTS("\033\\\f");
  323.  
  324. }
  325.  
  326. #include "prtpage.h"
  327. #include "readfont.h"
  328. #include "readgf.h"
  329. #include "readpk.h"
  330. #include "readpost.h"
  331. #include "readpxl.h"
  332. #include "reldfont.h"
  333. #include "rulepxl.h"
  334. #include "setchar.h"
  335. #include "setfntnm.h"
  336. #include "setrule.h"
  337. #include "signex.h"
  338. #include "skgfspec.h"
  339. #include "skipfont.h"
  340. #include "skpkspec.h"
  341. #include "special.h"
  342. #include "strchr.h"
  343. #include "strcm2.h"
  344. #include "strid2.h"
  345. #include "strrchr.h"
  346. #include "tctos.h"
  347. #include "usage.h"
  348. #include "warning.h"
  349.